package com.hopu.v1.config;


import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * jgb
 */
@Configuration
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {

    @Override //配置时间显示
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); // MappingJackson2HttpMessageConverter是springboot中默认的Json消息转换器
        converter.getObjectMapper().registerModule(new JavaTimeModule());
        converters.add(converter);
    }
//    @Autowired
//    private LoginInterceptor loginInterceptor;

//    @Autowired
//    private FrontLoginInterceptor frontLoginInterceptor;

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//       registry.addInterceptor(frontLoginInterceptor).addPathPatterns("/**").excludePathPatterns("/student/login", "/file/*");
//        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/staff/login", "/student/login","/file/*");
//    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("*")
                .allowedHeaders("*")
                .exposedHeaders("*")
                .allowCredentials(false).maxAge(3600);
    }

}
